﻿using cuiail.DBConnections;
using cuiail.DBModels;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Routing;
using System.Data;

namespace cuiail.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class InspectionRobotController : ControllerBase
    {
        private readonly IWorkingModeService _workingModeService;
        private readonly ICurrentWorkModeService _currentWorkModeService;
        private readonly IPrintContentService _printContentService;
        private readonly ILogger<LabController> _logger;


        public static _巡检机器人_POS_状态 inspectionRobotStatus { get; set; } = new _巡检机器人_POS_状态();
        public static _巡检机器人_GET_命令 inspectionRobotCommand { get; set; } = new _巡检机器人_GET_命令();

        public InspectionRobotController(IWorkingModeService workingModeService,ICurrentWorkModeService currentWorkModeService, IPrintContentService printContentService, ILogger<LabController> logger)
        {
            _currentWorkModeService = currentWorkModeService;
            _workingModeService = workingModeService;
            _printContentService= printContentService;
            _logger = logger;
        }


        /// <summary>
        /// 获取命令数据
        /// </summary>
        [HttpGet]
        [Route("GetCommandData")]
        public async Task<ActionResult<IEnumerable<_巡检机器人_GET_命令>>> GetCommandDataAsync()
        {
            try
            {
                //开始赋值，逻辑开始做起来了。
                if (CloudPlatformController.cloudPlatformPosWorkOrder != null)
                {
                  
                    inspectionRobotCommand._系统模式数据 = CloudPlatformController.cloudSystemModel.WorkingModeId;
                    inspectionRobotCommand._系统命令 = CloudPlatformController.cloudSystemCommand.SystemCommand;
                  //  inspectionRobotCommand._故障清除命令  = TransportRobotController.transportRobotStatus._当前工序状态;
                }
                var result = inspectionRobotCommand;
                return Ok(result);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "get命令数据发生错误");
                return StatusCode(500, "get命令数据时发生错误，请稍后重试");
            }
        }


        



        /// <summary>
        /// 写入巡检机器人状态数据
        /// </summary>
        /// <param name="currentWorkingMode">当前工作模式代码</param>
        /// <returns>写入成功或者失败</returns>
        [HttpPost]
        [Route("InsertInspectionRobotStatusData")]
        public async Task<ActionResult<bool>> InsertInspectionRobotStatusDataAsync(_巡检机器人_POS_状态 temp)
        {
            try
            {
                inspectionRobotStatus = temp;
                CloudPlatformController.cloudInspectionRobotStatus.Updatefrom巡检机器人_POS_状态(inspectionRobotStatus);

                var result = true;
                return Ok(result);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "写入巡检机器人状态数据时发生错误");
                return StatusCode(500, "写入巡检机器人状态数据时发生错误，请稍后重试");
            }
        }



        





       
    }
}
